{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "51f8b3cb",
   "metadata": {},
   "source": [
    "**2022/10/17 礼仪的week09**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f20940d1",
   "metadata": {},
   "source": [
    "# 本周学习知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0a6918e",
   "metadata": {},
   "source": [
    "> 1.用户输入\n",
    ">\n",
    ">\n",
    "> 2.文本的格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e968cfa8",
   "metadata": {},
   "source": [
    "## 1.用户输入"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e7f65b6",
   "metadata": {},
   "source": [
    "* input方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f7fd221f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: admin\n",
      "密码：123456\n"
     ]
    }
   ],
   "source": [
    "# 用户登入系统\n",
    "username = input(\"账号: \")\n",
    "password = input(\"密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6a9be2fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8f9ad913",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: njhdfl\n",
      "密码: 3333\n",
      "账号不存在或密码不正确！请重新输入！\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代1 增加判断\n",
    "user01 = \"admit\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号: \")\n",
    "password = input(\"密码: \")\n",
    "# 情景一：账号密码都对\n",
    "if user01 == username and  password01 == password:\n",
    "    print(\"登陆成功~欢迎\"+ user01)\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else: \n",
    "    print(\"账号不存在或密码不正确！请重新输入！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4da5237e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号: admin\n",
      "密码: 123456\n",
      "账号不存在或密码不正确！请重新输入！您还有2次尝试的机会\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 4>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      3\u001b[0m password01 \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m123456\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m0\u001b[39m,\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m):\n\u001b[1;32m----> 5\u001b[0m     username \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m账号: \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      6\u001b[0m     password \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m密码: \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      7\u001b[0m \u001b[38;5;66;03m# 情景一：账号密码都对\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代2 循环！ 5分钟，加油~ for + range()  10点35分 \n",
    "user01 = \"admit\"\n",
    "password01 = \"123456\"\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号: \")\n",
    "    password = input(\"密码: \")\n",
    "# 情景一：账号密码都对\n",
    "    if user01 == username and  password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+ user01)\n",
    "        break # 中止循环\n",
    "     # 情景二：账号不存在或密码不正确，用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确！请重新输入！您还有\"+str(i-1)+\"次尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！请1小时候再来尝试\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2cb1ca37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登陆成功~欢迎admin\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代2 循环！ 5分钟，加油~ for + range()  10点35分 \n",
    "\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and  password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "        break # 中止循环\n",
    "    # 情景二：账号不存在或密码不正确，用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确！请重新输入！您还有\"+str(i-1)+\"次尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！请1小时候再来尝试\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c11bc74e",
   "metadata": {},
   "source": [
    "# 2.字符串的格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c73b8ad",
   "metadata": {},
   "source": [
    "> 1.字符串的拼接\n",
    ">\n",
    "> 2.占位符\n",
    ">\n",
    "> 3.格式化输出的方法：format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4ff7a351",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOF while scanning triple-quoted string literal (<ipython-input-26-b486fb763362>, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-26-b486fb763362>\"\u001b[1;36m, line \u001b[1;32m13\u001b[0m\n\u001b[1;33m    print(info)\u001b[0m\n\u001b[1;37m               \n^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOF while scanning triple-quoted string literal\n"
     ]
    }
   ],
   "source": [
    "错误示范\n",
    "# 用户的信息输入（完善信息）： 占位符 s%\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区:\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO %s -------\n",
    "地区;%s\n",
    "工作;%s\n",
    "年龄：%s\n",
    "薪资期待：%\"'%（name，region，job，age ，salary）\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e5486a31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：深圳\n",
      "工作：产品经理助理\n",
      "年龄：22\n",
      "期待薪资：10K/月\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）：字符串的拼接\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO '''+ name + '''--------\n",
    "地区：'''+ region + '''\n",
    "工作：'''+ job + '''\n",
    "年龄：'''+ age + '''\n",
    "薪资期待：'''+salary\n",
    "# 好麻烦，好容易出错！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3f580270",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------INFO 李华--------\n",
      "地区：深圳\n",
      "工作：产品经理助理\n",
      "年龄：22\n",
      "薪资期待：10K/月\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "dfd25164",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：深圳\n",
      "工作：用户增长\n",
      "年龄：22\n",
      "期待薪资：10K\n",
      "---------INFO 李华 --------\n",
      "地区：深圳 \n",
      "工作：用户增长 \n",
      "年龄：22\n",
      "薪资期待：10K \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） : 占位符 s%\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO %s --------\n",
    "地区：%s \n",
    "工作：%s \n",
    "年龄：%s\n",
    "薪资期待：%s '''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "# 局限性：有序，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dc9b7d5d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：深圳\n",
      "工作：python web开发\n",
      "年龄：22\n",
      "期待薪资：18K/月\n",
      "---------INFO 李华 --------\n",
      "地区：深圳\n",
      "工作：python web开发 \n",
      "年龄：22\n",
      "薪资期待：18K/月 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） : format()\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO {昵称} --------\n",
    "地区：{地区}\n",
    "工作：{工作职位} \n",
    "年龄：{年龄}\n",
    "薪资期待：{薪资} '''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)\n",
    "# 书写规范，字符串中的 字段 一一对应，不考虑其顺序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f91d48ba",
   "metadata": {},
   "source": [
    "# 课后作业："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b0a8eef",
   "metadata": {},
   "source": [
    "> 1.第二章P93 前所有项目练习（下周讲）\n",
    ">\n",
    "> 2.购物车项目\n",
    ">>\n",
    ">> 要求:\n",
    ">>\n",
    ">> 1.运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    ">>\n",
    ">> 2.让用户输入商品编号进行商品的购买。\n",
    ">>\n",
    ">> 3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户\n",
    ">>\n",
    ">> 4.用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e681c4de",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
